import $app from "../$app";

export default {
    /**
     * 去掉字符串 所有的空格
     **/
    delSpace(num) {
        let out = '';
        if ($app.judgeData(num)) {
            let dd = num.toString();
            out = (dd.replace(/\s+/g, '')).replace(/\&nbsp\;/g, '');
        }
        return out;
    },

    // 判断不同文件显示不同icon =>这个函数仅适合服务猫项目 需配合 iconfont 使用
    fileIcon(nameObj) {
        
        let out = ' iconbuoumaotubiao25';
        if ($app.judgeData(nameObj)) {
            let string_fileUrl=$app.getVal_fileUrl(nameObj);
            let string_filePath=$app.getVal_filePath(nameObj);
            let string=string_fileUrl||string_filePath;
            if($app.judgeData(string)){
                if (/(pdf)$/i.test(string)) {
                    out = ' iconpdf ';//pdf 图标
                } else if (/(docx|doc)$/i.test(string)) {
                    out = ' iconWORD ';//word 图标
                } else if (/(jpeg|png|image|gif|bmp|jpg)$/i.test(string)) {
                    out = ' icontupian ';//word 图标
                } else if (/(zip)$/i.test(string)) {
                    out = ' icongeshi_yasuobaozip ';//zip
                } else if (/(rar)$/i.test(string)) {
                    out = ' icongeshi_yasuobaorar ';//rar
                } else{
                    out = ' iconwj-wj-1 ';//公共文件
                }
            }

        }
        return out;
    },





    //浮点数加减乘除运算
    //加法
    accAdd(arg1, arg2) {
        var r1, r2, m, c;
        try {
            r1 = arg1.toString().split(".")[1].length;
        }
        catch (e) {
            r1 = 0;
        }
        try {
            r2 = arg2.toString().split(".")[1].length;
        }
        catch (e) {
            r2 = 0;
        }
        c = Math.abs(r1 - r2);
        m = Math.pow(10, Math.max(r1, r2));
        if (c > 0) {
            var cm = Math.pow(10, c);
            if (r1 > r2) {
                arg1 = Number(arg1.toString().replace(".", ""));
                arg2 = Number(arg2.toString().replace(".", "")) * cm;
            } else {
                arg1 = Number(arg1.toString().replace(".", "")) * cm;
                arg2 = Number(arg2.toString().replace(".", ""));
            }
        } else {
            arg1 = Number(arg1.toString().replace(".", ""));
            arg2 = Number(arg2.toString().replace(".", ""));
        }
        return (arg1 + arg2) / m;
    },

    //减法
    accSub(arg1, arg2) {
        var r1, r2, m, n;
        try {
            r1 = arg1.toString().split(".")[1].length;
        }
        catch (e) {
            r1 = 0;
        }
        try {
            r2 = arg2.toString().split(".")[1].length;
        }
        catch (e) {
            r2 = 0;
        }
        m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
        n = (r1 >= r2) ? r1 : r2;
        return ((arg1 * m - arg2 * m) / m).toFixed(n);
    },

    //乘法
    accMul(arg1, arg2) {
        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
        try {
            m += s1.split(".")[1].length;
        }
        catch (e) {
        }
        try {
            m += s2.split(".")[1].length;
        }
        catch (e) {
        }
        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
    },

    //除法 项目里面好像没用用到除法
    // accDiv(arg1, arg2) {
    //     var t1 = 0, t2 = 0, r1, r2;
    //     try {
    //         t1 = arg1.toString().split(".")[1].length;
    //     }catch (e) {
    //     }
    //     try {
    //         t2 = arg2.toString().split(".")[1].length;
    //     } catch (e) {
    //     } with (Math) {
    //         r1 = Number(arg1.toString().replace(".", ""));
    //         r2 = Number(arg2.toString().replace(".", ""));
    //         return (r1 / r2) * pow(10, t2 - t1);
    //     }
    // }
}; 